package com.cci.kangdao.dao;


import com.cci.kangdao.cipFleet.entity.CipVehicleT;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;


@Mapper
public interface CipVehicleMapper {

    List<Map<String, Object>> getFleetEsnList(@Param("fleetId") Long fleetId, @Param("userId") Long userId,@Param("externalUserId") String externalUserId, @Param("type") Integer type);


    @Update("update Cip_Vehicle_T set Flag = -1,Deleter = #{userId},DeleteTime = #{time} \n" +
            "where Id in (select Id from Cip_Vehicle_T where Creator = #{userId} and ESN = #{esn} and Flag = 0)")
    int updateCipVehicleFlag(@Param("userId") Long userId, @Param("time") String time, @Param("esn") String esn);


    @Update("update Cip_Vehicle_T set Flag = #{flag},Deleter = #{userId},DeleteTime = #{updateTime} where FleetId = #{fleetId}")
    int deleteCipVehicleByFleetId(@Param("flag") int flag, @Param("userId") Long userId, @Param("updateTime") String updateTime, @Param("fleetId") Long fleetId);


    @Select("select b.ESN as esn,b.plateNumber as plateNumber,b.EsnPowerType as esnPowerType,\n" +
            "       b.EsnApplicationType as esnApplicationType \n" +
            "        from Cip_Vehicle_T a\n" +
            "            inner join ExternalCustomerESN_T b on a.ESN = b.ESN and a.ExternalUserId = b.UserId\n" +
            "            where a.Flag = 0 and a.FleetId = #{fleetId} and b.Flag = 0 and a.ExternalUserId = #{userId} and b.type = #{type}")
    List<Map<String, Object>> getExternalFleetEsnList(@Param("fleetId") Long fleetId, @Param("userId") String userId,
                                                      @Param("type") Integer type);

    List<CipVehicleT> getListByFleetId(@Param("fleetId")Long fleetId);
}
